package designpatterns.strategy;

import java.util.ArrayList;
import java.util.Arrays;

public class BubbleSort extends GeneralSort {
	@Override
	public ArrayList<Integer> sort(ArrayList <Integer> data) {
		internalData = data.toArray(new Integer[data.size()]);
		boolean unsorted = true;

		ExecTime = System.currentTimeMillis();

		while (unsorted) {
			unsorted = false;
			for (int i = 0; i < (internalData.length - 1); i++) {
				if (internalData[i+1] < internalData[i]) {
					swap(i, i+1);
					unsorted = true;
				}
			}
		}
		
		ExecTime = System.currentTimeMillis() - ExecTime;
		// TODO Auto-generated method stub
		return new ArrayList <Integer> (Arrays.asList(internalData));
	}

	@Override
    public String getName() {
	    // TODO Auto-generated method stub
	    return "Bubblesort " + isSorted();
    }


}
